const express = require('express')
const router = express.Router()
const models = require('../models')
const Result = require('../utils/Result')


router.get('/test', async (req, res) => {
    res.send('ok....')
})


/**
 *  @Router post /config/set
 *  @desc 新增标签
 *  @access 接口是私有的
 */
router.post('/set', async(req, res) => {
    const { title, desc,picture,type,articleId,typeId } = req.body
    const data = { title, desc,picture,type,articleId,typeId }
    const config = await models.Config.findOne({where:{type}})
    if(config){
        const {id} = config
        const result = await models.Config.update(data,{where:{id}})
        new Result(result,`操作成功`).success(res)
    }else{
        const result = await models.Config.create(data)
        new Result(result,`操作成功`).success(res)
    }
})



module.exports = router